﻿using System;
using System.Collections.Generic;
using ZyGames.DZPocker.Model;
using ZyGames.Framework.Cache.Generic;
using ZyGames.Framework.Game.Cache;
using ZyGames.Framework.Game.Context;
using ZyGames.Framework.Game.Contract;
using ZyGames.Framework.Game.Contract.Action;
using ZyGames.Framework.Game.Lang;
using ZyGames.Framework.Game.Service;
using System.Linq;
using ZyGames.DZPocker.Bll.Logic;
using ZyGames.DZPocker.Script;
using System.Text.RegularExpressions;
using ZyGames.DZPocker.Tools;
using ZyGames.Framework.Net;

namespace ZyGames.DZPocker.Script.CsScript.Action
{
	/// <summary>
	/// 30065_玩家申请发送表情
	/// </summary>
	public class Action30065 : BaseAction
	{
		private int tableId;
		private int userId;
		private int posId;
		/// <summary>
		/// 表情Name
		/// </summary>
		private string expName;
		private TableData _currentTable;
		private PositionData _currentPos;

		public Action30065(HttpGet actionGetter)
			: base((short)ActionType.DZApplySendExpression, actionGetter)
		{
		}
		public override bool GetUrlElement()
		{
			if (httpGet.GetInt("TableID", ref tableId) &&
				httpGet.GetInt("UserID", ref userId) &&
				httpGet.GetInt("PosID", ref posId) &&
				httpGet.GetString("ExpName", ref expName))
			{
				return true;
			}
			return false;
		}

		public override bool TakeAction()
		{
			_currentTable = GameRoom.Current.GetTableData(tableId);
			if (_currentTable == null)
			{
				Tool.WriteWarmingLine("消息30065获得房间不存在");
				return false;
			}
			var _currentGameUser = GameTable.Current.GetUser(userId);
			if (_currentGameUser == null)
			{
				Tool.WriteWarmingLine("消息30065玩家不存在");
				return false;
			}
			if (posId > _currentTable.PlayerNum)
			{
				Tool.WriteWarmingLine("消息30065座位号不合法");
				return false;
			}
			_currentPos = _currentTable.Positions[posId - 1];
			if (_currentPos == null)
			{
				Tool.WriteWarmingLine("消息30065座位号不存在");
				return false;
			}
			//广播给所有人消息
			var parameters = new Parameters();
			parameters["TableId"] = tableId;
			parameters["UserId"] = userId;
			parameters["PosId"] = posId;
			parameters["ExpName"] = expName;
			GameTable.Current.SyncNotifyAction((int)ActionType.DZBrocastSendExpression, _currentTable, parameters, t =>
			{
				Tool.WriteLine("广播消息30066 广播玩家发送的表情");
			});
			return true;
		}
	}
}
